<template>
  <div class="booking">
    <GhNavBar title="快速预约"   right-text="我的预约" @click-right="onClickRight" />
    <van-search
    class="search"
     placeholder="搜索"
    input-align="center"
 />
    <!-- <organizationInfo></organizationInfo> -->
    <div class="organizationInfo">
      <div class="head">
          <gh-icon name="notify-organization" class="icon"></gh-icon>
          <h3>心理咨询机构列表</h3>
      </div>
      <div class="content"  v-if="items.length>0">
        <div class="infoItem" v-for="item in items" :key="item.id" @click="toOrgConselor(item)">
          <div class="img-box">
          <img v-lazy="item.image" alt="" >
         </div>
         <div class="reduce-box">
          <p class="name">{{item.name}}</p>
          <p class="description">{{item.description}}</p>
         </div>
     </div>
      </div>
     
      <van-empty v-else  description="暂无机构信息" />


 </div>
  </div>
</template>

<script setup>
import { getOrganizationInfo} from '@/services/booking'
import {ref,reactive,onBeforeMount,computed,onMounted,watch} from "vue"
import { Toast, Dialog } from 'vant';
import 'vant/es/toast/style'
import{useRouter,useRoute}from 'vue-router'
const router =useRouter();  
const route =useRoute()

const items=ref([])

//第一次挂载时渲染结构信息
onBeforeMount(async()=>{
    const res =await getOrganizationInfo().then((response)=>{
      return response
    }).catch((error)=>{
     return error
    })
   if(res.status!==201){
   if(res.response.status==402){
        const toastMessage=res.response.data.error
        Toast.fail(toastMessage)
        isRegistering.value=false;
        return
    }
    if(res.response.status==404){
        const toastMessage=res.response.data.error
        Toast.fail(toastMessage)
        isRegistering.value=false;
        return
    }
  }
    // console.log(res.data)
    items.value=res.data
})

//点击进行咨询机构对应咨询师页面
const toOrgConselor=(item)=>{
  router.push(`/bookingCounselor/${item.org_id}`)
  console.log(item.org_id)
}


const onClickRight=()=>{
    router.push('/appointment/bookingHistory')
}
</script>

<style lang="scss" scoped>
.booking{
    background-color: var(--gh-bg);
    .search{
      position: fixed;
      width: 100%;
      z-index: 999;
      top: 40px;
      left: 0;
    }
    .organizationInfo{
      position: relative;
      margin-top: 80px;
      padding: 0 5px 0 20px;
    .head{
        position: fixed;
        top: 90px;
        width: 100%;
        background-color: #fff;
        z-index: 999;
        display: flex;
        align-items: center;
        .icon{
           margin-right: 5px;
         }
        h3{
        font-family: '楷体';
        font-size: 16px;
        margin: 5px 0;
       }
    }
  .content{
    margin-top: 120px;
    .infoItem{
        margin-bottom: 8px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        height: 100px;
        width: 100%;
        background: var(--gh-primary);
        .img-box{
            margin-left: 5px;
            height: 60px;
            width: 60px;
            img{
                border-radius: 50%;
                display: block;
                height: 100%;
                width: 100%;
            }
        }
        .reduce-box{
            display: flex;
            flex-direction: column;
            height: 100px;
            flex: 1;
            padding: 8px 0;
            font-family: '幼圆';
            margin-left: 10px;
            color: #fff;
           .name{
             font-size: 14px;
             font-weight: bold;
             line-height: 12px;
           }
           .description{
            font-family: '楷体';
             margin-top: 10px;
             font-size: 12px;
             display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3; /* 限制行数 */
            overflow: hidden; /* 超出范围隐藏 */
            text-overflow: ellipsis; /* 使用省略号表示文本溢出 */
           }
  
        }
    }
  }

}

    
}


</style>
